package cn.common.result;

import cn.common.exception.IError;
import lombok.Data;

@Data
public class Response {
    private String code;
    private String message;
    private Object result;
    private Status status;
    public Response() {
        this.status = Status.SUCCEED;
    }

     public Response(IError error) {
        this.code = error.getCode();
        this.message = error.getMessage();
        this.status = Status.FAILED;
     }

     public static Response Success(){
        return new Response();
     }
     public static Response Success(Object result){
         Response response = new Response();
         response.setResult(result);
         return response;
     }

     public static Response Failure(IError error){
          Response response = new Response();
          response.setCode(error.getCode());
          response.setMessage(error.getMessage());
          response.setStatus(Status.FAILED);
          return response;
     }

     public static Response Failure(String code,String message){
        Response response = new Response();
         response.setCode(code);
         response.setMessage(message);
         response.setStatus(Status.FAILED);
         return response;
     }

    public enum Status {
        /**
         * 状态
         */
        SUCCEED,
        WARRING,
        FAILED;

        Status() {
        }
    }
}
